package com.demo.widget.guhong;

import com.demo.widget.BaseAbility;
import com.demo.widget.ResourceTable;
import com.meis.widget.MeiLinePathView;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.render.Path;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT;

/**
 * desc:
 * author: wens
 * date: 2018/4/29.
 */
public class MeiLinePathAbility extends BaseAbility {
   private DependentLayout mFrameLayout;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_mei_line_path_ability);
        mFrameLayout = (DependentLayout) findComponentById(ResourceTable.Id_fl_content);
        setPath();
        startAnimation();
    }

   private void startAnimation() {
        for (int i = 0; i < mFrameLayout.getChildCount(); i++) {
            Component childView = mFrameLayout.getComponentAt(i);
            if (childView instanceof MeiLinePathView) {
                ((MeiLinePathView) childView).startAnimation();
            }
        }
    }

    private void setPath() {
        Path path1 = new Path();
        Path path2 = new Path();
        Path path3;
        Path path4;
        Path path5;
        Path path6;
        path1.moveTo(310, 0);
        path2.moveTo(410, 0);
        path1.lineTo(310, 400);
        path1.lineTo(210, 500);
        path1.lineTo(210, 600);
        path1.lineTo(310, 700);
        path1.lineTo(310, 1280);
        path2.lineTo(410, 400);
        path2.lineTo(510, 500);
        path2.lineTo(510, 600);
        path2.lineTo(410, 700);
        path2.lineTo(410, 1280);
        path3 = new Path(path1);
        path3.offset(-100, 0);
        path5 = new Path(path1);
        path5.offset(-200, 0);
        path4 = new Path(path2);
        path4.offset(+100, 0);
        path6 = new Path(path2);
        path6.offset(+200, 0);
        for (int i = 0; i < 6; i++) {
            MeiLinePathView pathView = new MeiLinePathView(MeiLinePathAbility.this);
            switch (i) {
                case 0:
                    pathView.setPath(path1);
                    break;
                case 1:
                    pathView.setPath(path2);
                    break;
                case 2:
                    pathView.setPath(path3);
                    pathView.setMode(MeiLinePathView.TRAIN_MODE);
                    break;
                case 3:
                    pathView.setPath(path4);
                    pathView.setMode(MeiLinePathView.TRAIN_MODE);
                    break;
                case 4:
                    pathView.setPath(path5);
                    break;
                case 5:
                    pathView.setPath(path6);
                    break;
            }
            pathView.setLayoutConfig(new DependentLayout.LayoutConfig(MATCH_PARENT,MATCH_PARENT));
            mFrameLayout.addComponent(pathView, 0);
        }
    }
}
